<?php
//Zend_Loader::loadFile('../application/admin/models/Template.php');
class Specialtext
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function getparentids()
    {

    	$getSpecialtexts = $this->_db->fetchAll("
			select id,title    from specialtext where parentid=0
		");
	//	print_r($getSpecialtexts);exit;
		return $getSpecialtexts;
	}

         public function listSpecialtexts()
    {
    	$this->_db->query("SET NAMES 'utf8'");
    	$getSpecialtexts = $this->_db->fetchAll("
			select * from specialtext
		");
	//	print_r($getSpecialtexts);exit;
		return $getSpecialtexts;
	}
	

    public function getSpecialtext($Specialtext_id)
    {
    //	echo $Specialtext_id;exit;
    	$this->_db->query("SET NAMES 'utf8'");
    	$getSpecialtextdetails = $this->_db->fetchRow("
			SELECT *
			FROM  specialtext
			WHERE  id='".$Specialtext_id."'
			
		");
		return $getSpecialtextdetails;
       
    }

    public function addSpecialtext($form_values)
    {
        $parentid = $form_values['parentid'];
        $title = $form_values['title'];
        $title_ru = $form_values['title_ru'];
        $description = $form_values['description'];
        $description_ru = $form_values['description_ru'];
        $status =  $form_values['status'];
        $this->_db->query("SET NAMES 'utf8'"); 
        $addSpecialtext = $this->_db->exec("
                INSERT INTO specialtext (title, title_ru, description, description_ru, status,type,parentid)
                VALUES ('" . $title . "','" . $title_ru . "','" . $description . "', '" . $description_ru . "', " . $status . ",1,".$parentid.")");
        
        if($addSpecialtext)
        {
            echo "Specialtext has been successfully created";
        }
    }

    public function updateSpecialtext($form_values)
    {
        $parentid= $form_values['parentid'];
        $id = $form_values['id'];
        $title = $form_values['title'];
        $title_ru = $form_values['title_ru'];
        $description = $form_values['description'];
        $description_ru = $form_values['description_ru'];
        $status = $form_values['status'];
        $this->_db->query("SET NAMES 'utf8'");
        $update_Specialtext = $this->_db->exec("
            UPDATE  specialtext
            SET   parentid=".$parentid.", title='" . $title . "' ,title_ru='" . $title_ru . "', description='" . $description . "', description_ru='" . $description_ru. "',status=".$status."
            WHERE  id=" . $id
        );
        
        if($update_Specialtext)
        {
            echo "Selected Specialtext details has been successfully updated";
        }
        else{
            echo "you did not change anything!";
        }
    }

    public function deleteSpecialtext($Specialtext_id)
    {
    	$sql = "DELETE FROM specialtext
    			WHERE   id = " . $Specialtext_id;
        //echo $sql;exit;
    	$delete_Specialtext = $this->_db->exec($sql);
    	
    	if($delete_Specialtext)
    	{
    		echo "Selected Specialtext has been successfully deleted";
    	}
	}
	
	public function getSubscribeUsers() 
	{
		$subs_user_arr = $this->_db->fetchAll("
			SELECT nletter_userid, nletter_email
			FROM nletter_users
			WHERE status = 1
		");
		
		return $subs_user_arr;
	}
	
	public function getSubscribeUsersByLang($lang)
	{
		$subuser_arr = $this->_db->fetchAll("
			SELECT nletter_userid, nletter_email
			FROM nletter_users
			WHERE lang = '" . $lang . "'
			AND status = 1
		");
		
		return $subuser_arr;
	}
}

